package com.jiudengnile.liushu.biz.dal.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jiudengnile.liushu.biz.dal.dao.PermissionUserDAO;
import com.jiudengnile.liushu.biz.dal.ibatis.base.BaseIbatisDaoSupport;
import com.jiudengnile.liushu.biz.domains.permission.PermissionUserDO;
import com.jiudengnile.liushu.biz.query.ListWithTotalCount;
import com.jiudengnile.liushu.biz.query.PermissionQuery;

public class PermissionUserDAOIbaits extends BaseIbatisDaoSupport implements PermissionUserDAO {
	
	public long create(PermissionUserDO permissionUser) {
		return (Long)this.getSqlMapClientTemplate().insert("PermissionUserDAO.create", permissionUser);
	}

	public void delete(long id) {
		this.getSqlMapClientTemplate().update("PermissionUserDAO.delete", id);
	}

	public void update(PermissionUserDO permissionUser) {
		this.getSqlMapClientTemplate().update("PermissionUserDAO.update", permissionUser);
	}

	public PermissionUserDO queryById(long id) {
		return (PermissionUserDO)this.getSqlMapClientTemplate().queryForObject("PermissionUserDAO.queryById", id);
	}
	
	@SuppressWarnings("unchecked")
	public ListWithTotalCount<PermissionUserDO> queryByUserForPage(PermissionQuery permissionQuery) {
		List<PermissionUserDO>  permissionUserDOs = (List<PermissionUserDO>)this.getSqlMapClientTemplate().queryForList("PermissionUserDAO.queryByUserForPage", permissionQuery);
		int count = (Integer)this.getSqlMapClientTemplate().queryForObject("PermissionUserDAO.queryByUserForCount", permissionQuery);
		ListWithTotalCount<PermissionUserDO> ret = new ListWithTotalCount<PermissionUserDO>(permissionUserDOs);
		ret.setTotalCount(count);
		return ret;
	}
	
	

	@SuppressWarnings("unchecked")
	@Override
	public ListWithTotalCount<PermissionUserDO> queryByPemissionForPage(PermissionQuery permissionQuery) {
		List<PermissionUserDO>  permissionUserDOs = (List<PermissionUserDO>)this.getSqlMapClientTemplate().queryForList("PermissionUserDAO.queryByPemissionForPage", permissionQuery);
		int count = (Integer)this.getSqlMapClientTemplate().queryForObject("PermissionUserDAO.queryByPemissionForCount", permissionQuery);
		ListWithTotalCount<PermissionUserDO> ret = new ListWithTotalCount<PermissionUserDO>(permissionUserDOs);
		ret.setTotalCount(count);
		return ret;
	}

	@Override
	public PermissionUserDO queryByUserAndCode(long userId, String permissionCode) {
		Map<String, Object> param = new HashMap<String, Object>(2);
		param.put("userId", userId);
		param.put("permissionCode", permissionCode);
		return (PermissionUserDO)this.getSqlMapClientTemplate().queryForObject("PermissionUserDAO.queryByUserAndCode", param);
	}


}
